{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Data Loading\n",
    "%pylab inline\n",
    "import pandas as pd\n",
    "\n",
    "# global path\n",
    "train_path = 'F:\\\\notebook\\\\ppd\\\\PPD-Second-Round-Data\\\\'\n",
    "\n",
    "# training data\n",
    "train_master = pd.read_csv(train_path+'Master_train_set.csv',index_col ='Idx',encoding='gb18030')\n",
    "train_user = pd.read_csv(train_path+'User_train_set.csv',index_col ='Idx',encoding='gb18030')\n",
    "train_log = pd.read_csv(train_path+'Log_train_set.csv',index_col ='Idx',encoding='gb18030')\n",
    "\n",
    "print \"train_master shape %d x %d\" %(train_master.shape[0],train_master.shape[1])\n",
    "print \"train_user shape %d x %d\" %(train_user.shape[0],train_user.shape[1])\n",
    "print \"train_log shape %d x %d\" %(train_log.shape[0],train_log.shape[1])\n",
    "\n",
    "# test data\n",
    "test_master = pd.read_csv(train_path+'Master_test_set.csv',index_col ='Idx',encoding='gb18030')\n",
    "test_user = pd.read_csv(train_path+'User_test_set.csv',index_col ='Idx',encoding='gb18030')\n",
    "test_log = pd.read_csv(train_path+'Log_test_set.csv',index_col ='Idx',encoding='gb18030')\n",
    "\n",
    "print \"test_master shape %d x %d\" %(test_master.shape[0],test_master.shape[1])\n",
    "print \"test_user shape %d x %d\" %(test_user.shape[0],test_user.shape[1])\n",
    "print \"test_log shape %d x %d\" %(test_log.shape[0],test_log.shape[1])\n",
    "\n",
    "# combine training and test data\n",
    "# fake target variable for append data\n",
    "test_master['target']=0\n",
    "test_master['test_ind']=1\n",
    "train_master['test_ind']=0\n",
    "\n",
    "# 50-50 split for train and val data\n",
    "from sklearn import cross_validation\n",
    "X_train, X_val = cross_validation.train_test_split(train_master , test_size=0.5, random_state=0)\n",
    "train_master.loc[X_val.index,'test_ind']=2\n",
    "\n",
    "train_master = train_master.append(test_master)\n",
    "train_user = train_user.append(test_user)\n",
    "train_log = train_log.append(test_log)\n",
    "\n",
    "print \"train_master shape %d x %d\" %(train_master.shape[0],train_master.shape[1])\n",
    "print \"train_user shape %d x %d\" %(train_user.shape[0],train_user.shape[1])\n",
    "print \"train_log shape %d x %d\" %(train_log.shape[0],train_log.shape[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Feature Engineering\n",
    "import string\n",
    "\n",
    "#User info update\n",
    "train_user['UserupdateInfo1'] = train_user.UserupdateInfo1.apply(lambda x:string.upper(x))\n",
    "train_user['ListingInfo1'] = pd.to_datetime(train_user.ListingInfo1,dayfirst=True)\n",
    "train_user['UserupdateInfo2'] = pd.to_datetime(train_user.UserupdateInfo2,dayfirst=True)\n",
    "train_user['UserupdateInfo2_weekday'] = train_user['UserupdateInfo2'].apply(lambda x:x.weekday())\n",
    "train_user['Daysupdatetolisting'] = train_user['ListingInfo1'] - train_user['UserupdateInfo2']\n",
    "train_user['Daysupdatetolisting'] = train_user['Daysupdatetolisting'].apply(lambda x: x.astype('timedelta64[D]').astype(int))\n",
    "\n",
    "#User's overall update(count and recency)\n",
    "train_part1 = pd.DataFrame(index = train_master.index)\n",
    "train_user_by = pd.DataFrame(train_user.groupby(level=0)['ListingInfo1'].count())\n",
    "train_user_by.columns = ['cnt_update']\n",
    "train_user_by['Daysupdatetolisting'] = train_user.groupby(level=0)['Daysupdatetolisting'].min()\n",
    "train_user_by['Daysfirsttolisting'] = train_user.groupby(level=0)['Daysupdatetolisting'].max()\n",
    "train_user_by['Duration_update'] = train_user_by['Daysfirsttolisting'] - train_user_by['Daysupdatetolisting']\n",
    "train_user_by['Daysupdatestd'] = train_user.groupby(level=0)['Daysupdatetolisting'].std()\n",
    "train_user_by['cnt_update_listday'] = train_user[train_user['Daysupdatetolisting']==0].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "df = train_user.join(train_user_by,how='left',rsuffix='_r')\n",
    "train_user_by['cnt_first_update'] = df[df['Daysupdatetolisting']==df['Daysfirsttolisting']].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "train_user_by['ratio_cnt_first_update'] = train_user_by['cnt_first_update']/train_user_by['cnt_update']\n",
    "train_part1 = train_part1.join(train_user_by,how='left')\n",
    "train_part1.fillna({'cnt_update':0,'Daysupdatetolisting':9999,'Daysfirsttolisting':9999,'cnt_update_listday':0,'Daysupdatestd':0,\\\n",
    "              'Duration_update':0,'cnt_first_update':0,'ratio_cnt_first_update':0},inplace=True)\n",
    "train_part1['cnt_update_days_listday'] = train_user.groupby(level=0)['Daysupdatetolisting'].apply(lambda x: x.nunique())\n",
    "train_part1['days_between_two_update'] = train_part1['Duration_update']/train_part1['cnt_update_days_listday']\n",
    "train_part1['cnt_update_days_listday'].fillna(0, inplace = True)\n",
    "train_part1['days_between_two_update'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_cnt_listday'] = train_user.groupby(level=0)['UserupdateInfo1'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_cnt_listday'].fillna(0, inplace = True)\n",
    "\n",
    "\n",
    "#User's update by category\n",
    "df=train_user.reset_index().set_index(['Idx','UserupdateInfo1']).groupby(level=['Idx','UserupdateInfo1']).count().reset_index()\n",
    "df['UserupdateInfo1'] = df.UserupdateInfo1.apply(lambda x:'cnt'+x)\n",
    "df = df.pivot(index='Idx', columns='UserupdateInfo1', values='ListingInfo1')\n",
    "train_part1 = train_part1.join(df,how='left')\n",
    "train_part1.fillna(0,inplace=True)\n",
    "\n",
    "#User's update by recency\n",
    "df=train_user.reset_index().set_index(['Idx','UserupdateInfo1']).groupby(level=['Idx','UserupdateInfo1']).min().reset_index()\n",
    "df['UserupdateInfo1'] = df.UserupdateInfo1.apply(lambda x:'dayslast'+x)\n",
    "df = df.pivot(index='Idx', columns='UserupdateInfo1', values='Daysupdatetolisting')\n",
    "train_part1 = train_part1.join(df,how='left')\n",
    "train_part1.fillna(-9999,inplace=True)\n",
    "\n",
    "#User's update by first update\n",
    "df=train_user.reset_index().set_index(['Idx','UserupdateInfo1']).groupby(level=['Idx','UserupdateInfo1']).max().reset_index()\n",
    "df['UserupdateInfo1'] = df.UserupdateInfo1.apply(lambda x:'daysfirst'+x)\n",
    "df = df.pivot(index='Idx', columns='UserupdateInfo1', values='Daysupdatetolisting')\n",
    "train_part1 = train_part1.join(df,how='left')\n",
    "train_part1.fillna(0,inplace=True)\n",
    "\n",
    "#User's update by weekday\n",
    "df=train_user.reset_index().set_index(['Idx','UserupdateInfo2_weekday']).groupby(level=['Idx','UserupdateInfo2_weekday']).count().reset_index()\n",
    "df['UserupdateInfo2_weekday'] = df.UserupdateInfo2_weekday.apply(lambda x:'cnt_weekday'+str(x))\n",
    "df = df.pivot(index='Idx', columns='UserupdateInfo2_weekday', values='ListingInfo1')\n",
    "train_part1 = train_part1.join(df,how='left')\n",
    "train_part1.fillna(0,inplace=True)\n",
    "\n",
    "\n",
    "#train['cnt_update_listday_0'] = train_user[train_user['Daysupdatetolisting']==0].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "#train['cnt_update_listday_0'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_cnt_listday_0'] = train_user[train_user['Daysupdatetolisting']==0].groupby(level=0)['UserupdateInfo1'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_cnt_listday_0'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_listday_3'] = train_user[train_user['Daysupdatetolisting']<=3].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "train_part1['cnt_update_listday_3'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_days_listday_3'] = train_user[train_user['Daysupdatetolisting']<=3].groupby(level=0)['Daysupdatetolisting'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_days_listday_3'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_cnt_listday_3'] = train_user[train_user['Daysupdatetolisting']<=3].groupby(level=0)['UserupdateInfo1'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_cnt_listday_3'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_listday_7'] = train_user[train_user['Daysupdatetolisting']<=7].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "train_part1['cnt_update_listday_7'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_days_listday_7'] = train_user[train_user['Daysupdatetolisting']<=7].groupby(level=0)['Daysupdatetolisting'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_days_listday_7'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_cnt_listday_7'] = train_user[train_user['Daysupdatetolisting']<=7].groupby(level=0)['UserupdateInfo1'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_cnt_listday_7'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_listday_15'] = train_user[train_user['Daysupdatetolisting']<=15].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "train_part1['cnt_update_listday_15'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_days_listday_15'] = train_user[train_user['Daysupdatetolisting']<=15].groupby(level=0)['Daysupdatetolisting'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_days_listday_15'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_cnt_listday_15'] = train_user[train_user['Daysupdatetolisting']<=15].groupby(level=0)['UserupdateInfo1'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_cnt_listday_15'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_listday_30'] = train_user[train_user['Daysupdatetolisting']<=30].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "train_part1['cnt_update_listday_30'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_days_listday_30'] = train_user[train_user['Daysupdatetolisting']<=30].groupby(level=0)['Daysupdatetolisting'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_days_listday_30'].fillna(0, inplace = True)\n",
    "train_part1['cnt_update_cnt_listday_30'] = train_user[train_user['Daysupdatetolisting']<=30].groupby(level=0)['UserupdateInfo1'].apply(lambda x: x.nunique())\n",
    "train_part1['cnt_update_cnt_listday_30'].fillna(0, inplace = True)\n",
    "\n",
    "list_tmp = train_user['UserupdateInfo1'].value_counts().index.values.tolist()\n",
    "for item in list_tmp:\n",
    "    train_part1['cnt_update'+item+'_listday_0'] = train_user[(train_user['Daysupdatetolisting']==0)&(train_user['UserupdateInfo1']==item)].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "    train_part1['cnt_update'+item+'_listday_0'].fillna(0, inplace = True)\n",
    "    train_part1['cnt_update'+item+'_listday_3'] = train_user[(train_user['Daysupdatetolisting']<=3)&(train_user['UserupdateInfo1']==item)].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "    train_part1['cnt_update'+item+'_listday_3'].fillna(0, inplace = True)\n",
    "    train_part1['cnt_update'+item+'_listday_7'] = train_user[(train_user['Daysupdatetolisting']<=7)&(train_user['UserupdateInfo1']==item)].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "    train_part1['cnt_update'+item+'_listday_7'].fillna(0, inplace = True)\n",
    "    train_part1['cnt_update'+item+'_listday_15'] = train_user[(train_user['Daysupdatetolisting']<=15)&(train_user['UserupdateInfo1']==item)].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "    train_part1['cnt_update'+item+'_listday_15'].fillna(0, inplace = True)\n",
    "    train_part1['cnt_update'+item+'_listday_30'] = train_user[(train_user['Daysupdatetolisting']<=30)&(train_user['UserupdateInfo1']==item)].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "    train_part1['cnt_update'+item+'_listday_30'].fillna(0, inplace = True)\n",
    "    train_part1['cnt_update'+item+'_listday'] = train_user[train_user['UserupdateInfo1']==item].groupby(level=0)['Daysupdatetolisting'].count()\n",
    "    train_part1['cnt_update'+item+'_listday'].fillna(0, inplace = True)\n",
    "    train_part1['ratio_cnt_update'+item+'_listday'] = train_part1['cnt_update'+item+'_listday']/train_part1['cnt_update']\n",
    "    train_part1['ratio_cnt_update'+item+'_listday'].fillna(0, inplace = True)\n",
    "    train_part1['cnt_update_days'+item+'_listday'] = train_user[train_user['UserupdateInfo1']==item].groupby(level=0)['Daysupdatetolisting'].apply(lambda x: x.nunique())\n",
    "    train_part1['cnt_update_days'+item+'_listday'].fillna(0, inplace = True)\n",
    "\n",
    "train_part1['cnt_update_2moreitem_listday_0'] = train_part1[train_part1[['cnt_update'+item+'_listday_0' for item in list_tmp]]>1][['cnt_update'+item+'_listday_0' for item in list_tmp]].count(axis=1)\n",
    "train_part1['cnt_update_2moreitem_listday_3'] = train_part1[train_part1[['cnt_update'+item+'_listday_3' for item in list_tmp]]>1][['cnt_update'+item+'_listday_3' for item in list_tmp]].count(axis=1)\n",
    "train_part1['cnt_update_2moreitem_listday_7'] = train_part1[train_part1[['cnt_update'+item+'_listday_7' for item in list_tmp]]>1][['cnt_update'+item+'_listday_7' for item in list_tmp]].count(axis=1)\n",
    "train_part1['cnt_update_2moreitem_listday_15'] = train_part1[train_part1[['cnt_update'+item+'_listday_15' for item in list_tmp]]>1][['cnt_update'+item+'_listday_15' for item in list_tmp]].count(axis=1)\n",
    "train_part1['cnt_update_2moreitem_listday_30'] = train_part1[train_part1[['cnt_update'+item+'_listday_30' for item in list_tmp]]>1][['cnt_update'+item+'_listday_30' for item in list_tmp]].count(axis=1)\n",
    "train_part1['cnt_update_2moreitem_listday'] = train_part1[train_part1[['cnt_update'+item+'_listday' for item in list_tmp]]>1]\\\n",
    "[['cnt_update'+item+'_listday' for item in list_tmp]].count(axis=1)\n",
    "train_part1['cnt_update_3moreitem_listday'] = train_part1[train_part1[['cnt_update'+item+'_listday' for item in list_tmp]]>2]\\\n",
    "[['cnt_update'+item+'_listday' for item in list_tmp]].count(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#User log\n",
    "train_log['Listinginfo1'] = pd.to_datetime(train_log.Listinginfo1,dayfirst=True)\n",
    "train_log['LogInfo3'] = pd.to_datetime(train_log.LogInfo3,dayfirst=True)\n",
    "train_log['LogInfo3_weekday'] = train_log['LogInfo3'].apply(lambda x:x.weekday())\n",
    "train_log['LogInfo4'] = train_log['LogInfo2'].apply(lambda x: str(x)+'_') + train_log['LogInfo1'].apply(lambda x: str(x))\n",
    "train_log['Dayslogtolisting'] = train_log['Listinginfo1'] - train_log['LogInfo3']\n",
    "train_log['Dayslogtolisting'] = train_log['Dayslogtolisting'].apply(lambda x: x.astype('timedelta64[D]').astype(int))\n",
    "\n",
    "#User's overall log(count and recency)\n",
    "train_part2 = pd.DataFrame(index = train_master.index)\n",
    "\n",
    "train_log_by = pd.DataFrame(train_log.groupby(level=0)['Listinginfo1'].count())\n",
    "train_log_by.columns = ['cnt_log']\n",
    "train_log_by['Dayslogtolisting'] = train_log.groupby(level=0)['Dayslogtolisting'].min()\n",
    "train_log_by['Daysfirstlogtolisting'] = train_log.groupby(level=0)['Dayslogtolisting'].max()\n",
    "train_log_by['Duration_log'] = train_log_by['Daysfirstlogtolisting'] - train_log_by['Dayslogtolisting']\n",
    "train_log_by['Dayslogstd'] = train_log.groupby(level=0)['Dayslogtolisting'].std()\n",
    "train_log_by['cnt_log_listday'] = train_log[train_log['Dayslogtolisting']==0].groupby(level=0)['Dayslogtolisting'].count()\n",
    "df = train_log.join(train_log_by,how='left',rsuffix='_r')\n",
    "train_log_by['cnt_first_log'] = df[df['Dayslogtolisting']==df['Daysfirstlogtolisting']].groupby(level=0)['Dayslogtolisting'].count()\n",
    "df = train_log.reset_index().groupby(['Idx','Dayslogtolisting']).count()\n",
    "train_log_by['days_since_most_log'] = df[df['Listinginfo1'] == df.groupby(level=0)['Listinginfo1'].transform(max)].reset_index().groupby('Idx')['Dayslogtolisting'].min()\n",
    "train_log_by['ratio_cnt_first_log'] = train_log_by['cnt_first_log']/train_log_by['cnt_log']\n",
    "train_part2 = train_part2.join(train_log_by,how='left')\n",
    "train_part2.fillna({'cnt_log':0,'Dayslogtolisting':9999,'Daysfirstlogtolisting':9999,'cnt_log_listday':0,'Dayslogstd':0,\\\n",
    "              'Duration_log':0,'cnt_first_log':0,'days_since_most_log':0,'ratio_cnt_first_log':0},inplace=True)\n",
    "train_part2['cnt_log_days_listday'] = train_log.groupby(level=0)['Dayslogtolisting'].apply(lambda x: x.nunique())\n",
    "train_part2['days_between_two_log'] = train_part2['Duration_log']/train_part2['cnt_log_days_listday']\n",
    "train_part2['avg_cnt_log'] = train_part2['cnt_log']/train_part2['cnt_log_days_listday']\n",
    "train_part2['cnt_log_days_listday'].fillna(0, inplace = True)\n",
    "train_part2['days_between_two_log'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_typecnt_listday'] = train_log.groupby(level=0)['LogInfo2'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_typecnt_listday'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_actcnt_listday'] = train_log.groupby(level=0)['LogInfo1'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_actcnt_listday'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_type_actcnt_listday'] = train_log.groupby(level=0)['LogInfo4'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_type_actcnt_listday'].fillna(0, inplace = True)\n",
    "\n",
    "\n",
    "\n",
    "#User's log by type*action\n",
    "df=train_log.reset_index().set_index(['Idx','LogInfo4']).groupby(level=['Idx','LogInfo4']).count().reset_index()\n",
    "df['LogInfo4'] = df.LogInfo4.apply(lambda x:'cnt_type_act_'+str(x))\n",
    "df = df.pivot(index='Idx', columns='LogInfo4', values='Listinginfo1')\n",
    "train_part2 = train_part2.join(df,how='left')\n",
    "train_part2.fillna(0,inplace=True)\n",
    "\n",
    "#User's log by weekday\n",
    "df=train_log.reset_index().set_index(['Idx','LogInfo3_weekday']).groupby(level=['Idx','LogInfo3_weekday']).count().reset_index()\n",
    "df['LogInfo3_weekday'] = df.LogInfo3_weekday.apply(lambda x:'cnt_log_weekday'+str(x))\n",
    "df = df.pivot(index='Idx', columns='LogInfo3_weekday', values='Listinginfo1')\n",
    "train_part2 = train_part2.join(df,how='left')\n",
    "train_part2.fillna(0,inplace=True)\n",
    "\n",
    "\n",
    "#User's log by type*action*recency\n",
    "df=train_log.reset_index().set_index(['Idx','LogInfo4']).groupby(level=['Idx','LogInfo4']).min().reset_index()\n",
    "df['LogInfo4'] = df.LogInfo4.apply(lambda x:'dayslast_type_act_'+str(x))\n",
    "df = df.pivot(index='Idx', columns='LogInfo4', values='Dayslogtolisting')\n",
    "train_part2 = train_part2.join(df,how='left')\n",
    "train_part2.fillna(-9999,inplace=True)\n",
    "\n",
    "#User's log by type*action*recency\n",
    "df=train_log.reset_index().set_index(['Idx','LogInfo4']).groupby(level=['Idx','LogInfo4']).max().reset_index()\n",
    "df['LogInfo4'] = df.LogInfo4.apply(lambda x:'daysfirst_type_act_'+str(x))\n",
    "df = df.pivot(index='Idx', columns='LogInfo4', values='Dayslogtolisting')\n",
    "train_part2 = train_part2.join(df,how='left')\n",
    "train_part2.fillna(-9999,inplace=True)\n",
    "\n",
    "#train['cnt_log_listday_0'] = train_log[train_log['Dayslogtolisting']==0].groupby(level=0)['Dayslogtolisting'].count()\n",
    "#train['cnt_log_listday_0'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_type_actcnt_listday_0'] = train_log[train_log['Dayslogtolisting']==0].groupby(level=0)['LogInfo4'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_type_actcnt_listday_0'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_listday_3'] = train_log[train_log['Dayslogtolisting']<=3].groupby(level=0)['Dayslogtolisting'].count()\n",
    "train_part2['cnt_log_listday_3'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_days_listday_3'] = train_log[train_log['Dayslogtolisting']<=3].groupby(level=0)['Dayslogtolisting'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_days_listday_3'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_type_actcnt_listday_3'] = train_log[train_log['Dayslogtolisting']<=3].groupby(level=0)['LogInfo4'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_type_actcnt_listday_3'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_listday_7'] = train_log[train_log['Dayslogtolisting']<=7].groupby(level=0)['Dayslogtolisting'].count()\n",
    "train_part2['cnt_log_listday_7'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_days_listday_7'] = train_log[train_log['Dayslogtolisting']<=7].groupby(level=0)['Dayslogtolisting'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_days_listday_7'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_type_actcnt_listday_7'] = train_log[train_log['Dayslogtolisting']<=7].groupby(level=0)['LogInfo4'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_type_actcnt_listday_7'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_listday_15'] = train_log[train_log['Dayslogtolisting']<=15].groupby(level=0)['Dayslogtolisting'].count()\n",
    "train_part2['cnt_log_listday_15'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_days_listday_15'] = train_log[train_log['Dayslogtolisting']<=15].groupby(level=0)['Dayslogtolisting'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_days_listday_15'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_type_actcnt_listday_15'] = train_log[train_log['Dayslogtolisting']<=15].groupby(level=0)['LogInfo4'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_type_actcnt_listday_15'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_listday_30'] = train_log[train_log['Dayslogtolisting']<=30].groupby(level=0)['Dayslogtolisting'].count()\n",
    "train_part2['cnt_log_listday_30'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_days_listday_30'] = train_log[train_log['Dayslogtolisting']<=30].groupby(level=0)['Dayslogtolisting'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_days_listday_30'].fillna(0, inplace = True)\n",
    "train_part2['cnt_log_type_actcnt_listday_30'] = train_log[train_log['Dayslogtolisting']<=30].groupby(level=0)['LogInfo4'].apply(lambda x: x.nunique())\n",
    "train_part2['cnt_log_type_actcnt_listday_30'].fillna(0, inplace = True)\n",
    "\n",
    "\n",
    "list_tmp = train_log['LogInfo4'].value_counts().index.values.tolist()\n",
    "for item in list_tmp:\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_0'] = train_log[(train_log['Dayslogtolisting']==0)&(train_log['LogInfo4']==item)].groupby(level=0)['Dayslogtolisting'].count()\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_0'].fillna(0, inplace = True)\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_3'] = train_log[(train_log['Dayslogtolisting']<=3)&(train_log['LogInfo4']==item)].groupby(level=0)['Dayslogtolisting'].count()\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_3'].fillna(0, inplace = True)\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_7'] = train_log[(train_log['Dayslogtolisting']<=7)&(train_log['LogInfo4']==item)].groupby(level=0)['Dayslogtolisting'].count()\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_7'].fillna(0, inplace = True)\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_15'] = train_log[(train_log['Dayslogtolisting']<=15)&(train_log['LogInfo4']==item)].groupby(level=0)['Dayslogtolisting'].count()\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_15'].fillna(0, inplace = True)\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_30'] = train_log[(train_log['Dayslogtolisting']<=30)&(train_log['LogInfo4']==item)].groupby(level=0)['Dayslogtolisting'].count()\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday_30'].fillna(0, inplace = True)\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday'] = train_log[train_log['LogInfo4']==item].groupby(level=0)['Dayslogtolisting'].count()\n",
    "    train_part2['cnt_loginfo4'+str(item)+'_listday'].fillna(0, inplace = True)\n",
    "    train_part2['ratio_cnt_loginfo4'+str(item)+'_listday'] = train_part2['cnt_loginfo4'+str(item)+'_listday']/train_part2['cnt_log']\n",
    "    train_part2['ratio_cnt_loginfo4'+str(item)+'_listday'].fillna(0, inplace = True)\n",
    "    train_part2['cnt_log4_days'+str(item)+'_listday'] = train_log[train_log['LogInfo4']==item].groupby(level=0)['Dayslogtolisting'].apply(lambda x: x.nunique())\n",
    "    train_part2['cnt_log4_days'+str(item)+'_listday'].fillna(0, inplace = True)\n",
    "\n",
    "train_part2['cnt_log_2moretype_act_listday_0'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_0' for item in list_tmp]]>1][['cnt_loginfo4'+str(item)+'_listday_0' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_2moretype_act_listday_3'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_3' for item in list_tmp]]>1][['cnt_loginfo4'+str(item)+'_listday_3' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_2moretype_act_listday_7'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_7' for item in list_tmp]]>1][['cnt_loginfo4'+str(item)+'_listday_7' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_2moretype_act_listday_15'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_15' for item in list_tmp]]>1][['cnt_loginfo4'+str(item)+'_listday_15' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_2moretype_act_listday_30'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_30' for item in list_tmp]]>1][['cnt_loginfo4'+str(item)+'_listday_30' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_2moretype_act_listday'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday' for item in list_tmp]]>1][['cnt_loginfo4'+str(item)+'_listday' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_5moretype_act_listday_0'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_0' for item in list_tmp]]>4][['cnt_loginfo4'+str(item)+'_listday_0' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_5moretype_act_listday_3'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_3' for item in list_tmp]]>4][['cnt_loginfo4'+str(item)+'_listday_3' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_5moretype_act_listday_7'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_7' for item in list_tmp]]>4][['cnt_loginfo4'+str(item)+'_listday_7' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_5moretype_act_listday_15'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_15' for item in list_tmp]]>4][['cnt_loginfo4'+str(item)+'_listday_15' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_5moretype_act_listday_30'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_30' for item in list_tmp]]>4][['cnt_loginfo4'+str(item)+'_listday_30' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_5moretype_act_listday'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday' for item in list_tmp]]>4][['cnt_loginfo4'+str(item)+'_listday' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_10moretype_act_listday_0'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_0' for item in list_tmp]]>9][['cnt_loginfo4'+str(item)+'_listday_0' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_10moretype_act_listday_3'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_3' for item in list_tmp]]>9][['cnt_loginfo4'+str(item)+'_listday_3' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_10moretype_act_listday_7'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_7' for item in list_tmp]]>9][['cnt_loginfo4'+str(item)+'_listday_7' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_10moretype_act_listday_15'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_15' for item in list_tmp]]>9][['cnt_loginfo4'+str(item)+'_listday_15' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_10moretype_act_listday_30'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday_30' for item in list_tmp]]>9][['cnt_loginfo4'+str(item)+'_listday_30' for item in list_tmp]].count(axis=1)\n",
    "train_part2['cnt_log_10moretype_act_listday'] = train_part2[train_part2[['cnt_loginfo4'+str(item)+'_listday' for item in list_tmp]]>9][['cnt_loginfo4'+str(item)+'_listday' for item in list_tmp]].count(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Master Data\n",
    "\n",
    "# aggregation functions\n",
    "def msn(input):\n",
    "    length = 0\n",
    "    for item in input.tolist():\n",
    "        if item!=-1:\n",
    "            return length\n",
    "        else:\n",
    "            length += 1\n",
    "            \n",
    "def msz(input):\n",
    "    length = 0\n",
    "    for item in input.tolist():\n",
    "        if item>0:\n",
    "            return length\n",
    "        else:\n",
    "            length += 1\n",
    "            \n",
    "def msx(input):\n",
    "    length = 0\n",
    "    max_value = input.max()\n",
    "    for item in input.tolist():\n",
    "        if item==max_value:\n",
    "            return length\n",
    "        else:\n",
    "            length += 1\n",
    "\n",
    "def num(input):\n",
    "    length = 0\n",
    "    for item in input.tolist():\n",
    "        if item>-1:\n",
    "            length += 1\n",
    "    return length\n",
    "\n",
    "def nuz(input):\n",
    "    length = 0\n",
    "    for item in input.tolist():\n",
    "        if item>0:\n",
    "            length += 1\n",
    "    return length\n",
    "# cap and floor\n",
    "\n",
    "'''train_master[train_master['WeblogInfo_9']>=1]['WeblogInfo_9']=1\n",
    "train_master[train_master['WeblogInfo_8']>=7]['WeblogInfo_8']=7\n",
    "train_master[train_master['WeblogInfo_7']>=26]['WeblogInfo_7']=26\n",
    "train_master[train_master['WeblogInfo_6']>=10]['WeblogInfo_6']=10\n",
    "train_master[train_master['WeblogInfo_5']>=7]['WeblogInfo_5']=7\n",
    "train_master[train_master['WeblogInfo_4']>=11]['WeblogInfo_4']=11\n",
    "train_master[train_master['WeblogInfo_18']>=10]['WeblogInfo_18']=10\n",
    "train_master[train_master['WeblogInfo_17']>=16]['WeblogInfo_17']=16\n",
    "train_master[train_master['WeblogInfo_16']>=10]['WeblogInfo_16']=10\n",
    "train_master[train_master['WeblogInfo_15']>=8]['WeblogInfo_15']=8\n",
    "train_master[train_master['WeblogInfo_14']>=5]['WeblogInfo_14']=5\n",
    "train_master[train_master['SocialNetwork_9']>=500]['SocialNetwork_9']=500\n",
    "train_master[train_master['SocialNetwork_8']>=100]['SocialNetwork_8']=100\n",
    "train_master[train_master['SocialNetwork_6']>=1]['SocialNetwork_6']=1\n",
    "train_master[train_master['SocialNetwork_5']>=0]['SocialNetwork_5']=0\n",
    "train_master[train_master['SocialNetwork_4']>=0]['SocialNetwork_4']=0\n",
    "train_master[train_master['SocialNetwork_3']>=0]['SocialNetwork_3']=0\n",
    "train_master[train_master['SocialNetwork_10']>=200]['SocialNetwork_10']=200'''\n",
    "train_master[train_master['UserInfo_24']!='D']['UserInfo_24']='N'\n",
    "train_master['WeblogInfo_20'].fillna('N').apply(lambda x: x[0])\n",
    "\n",
    "\n",
    "train_master['ListingInfo'] = pd.to_datetime(train_master.ListingInfo,dayfirst=True)\n",
    "train_master['ListingInfo_M'] = train_master['ListingInfo'].values.astype('M8[M]')\n",
    "train_master['ListingInfo_weekday'] = train_master['ListingInfo'].apply(lambda x:x.weekday())\n",
    "train_master['ListingInfo_weekno'] = train_master['ListingInfo'].apply(lambda x:100*x.isocalendar()[0]+x.isocalendar()[1])\n",
    "\n",
    "train_master['less_nation_info2'] = train_master['UserInfo_2'].fillna('none').apply(lambda x:1 if u\"自治州\" in x else 0)\n",
    "train_master['less_nation_info4'] = train_master['UserInfo_4'].fillna('none').apply(lambda x:1 if u\"自治州\" in x else 0)\n",
    "train_master['less_nation_info8'] = train_master['UserInfo_8'].fillna('none').apply(lambda x:1 if u\"自治州\" in x else 0)\n",
    "\n",
    "city_ref = pd.read_csv(train_path+'provinc_city_lookup.csv',encoding='gb18030',names=['city','province','class'])\n",
    "train_master['UserInfo_2_province'] = train_master.merge(right =city_ref,how='left', left_on='UserInfo_2',right_on='city')['province'].values\n",
    "train_master['UserInfo_4_province'] = train_master.merge(right =city_ref,how='left', left_on='UserInfo_4',right_on='city')['province'].values\n",
    "train_master['UserInfo_2_class'] = train_master.merge(right =city_ref,how='left', left_on='UserInfo_2',right_on='city')['class'].values\n",
    "train_master['UserInfo_4_class'] = train_master.merge(right =city_ref,how='left', left_on='UserInfo_4',right_on='city')['class'].values\n",
    "\n",
    "train_master['UserInfo_7_unknown'] = train_master['UserInfo_7']==u\"不详\"\n",
    "train_master['UserInfo_20_unknown'] = train_master['UserInfo_20']==u\"不详\"\n",
    "\n",
    "train_master['UserInfo_2_4_same'] = train_master['UserInfo_2']==train_master['UserInfo_4']\n",
    "train_master['UserInfo_2_4_province_same'] = train_master['UserInfo_2_province']==train_master['UserInfo_4_province']\n",
    "train_master['UserInfo_2_8_same'] = (train_master['UserInfo_2']==train_master['UserInfo_8'])|(train_master['UserInfo_2']+u\"市\"==train_master['UserInfo_8'])\n",
    "train_master['UserInfo_2_8_province_same'] = (train_master['UserInfo_2_province']==train_master['UserInfo_7'])|(train_master['UserInfo_2_province']+u\"省\"==train_master['UserInfo_7'])\n",
    "train_master['UserInfo_2_20_same'] = (train_master['UserInfo_2']==train_master['UserInfo_20'])|(train_master['UserInfo_2']+u\"市\"==train_master['UserInfo_20'])\n",
    "train_master['UserInfo_2_20_province_same'] = (train_master['UserInfo_2_province']==train_master['UserInfo_19'])|(train_master['UserInfo_2_province']+u\"省\"==train_master['UserInfo_19'])\n",
    "\n",
    "train_master['UserInfo_4_8_same'] = (train_master['UserInfo_4']==train_master['UserInfo_8'])|(train_master['UserInfo_4']+u\"市\"==train_master['UserInfo_8'])\n",
    "train_master['UserInfo_4_8_province_same'] = (train_master['UserInfo_4_province']==train_master['UserInfo_7'])|(train_master['UserInfo_4_province']+u\"省\"==train_master['UserInfo_7'])\n",
    "train_master['UserInfo_4_20_same'] = (train_master['UserInfo_4']==train_master['UserInfo_20'])|(train_master['UserInfo_4']+u\"市\"==train_master['UserInfo_20'])\n",
    "train_master['UserInfo_4_20_province_same'] = (train_master['UserInfo_4_province']==train_master['UserInfo_19'])|(train_master['UserInfo_4_province']+u\"省\"==train_master['UserInfo_19'])\n",
    "\n",
    "train_master['UserInfo_8_20_same'] = (train_master['UserInfo_8']==train_master['UserInfo_20'])|(train_master['UserInfo_8']+u\"市\"==train_master['UserInfo_20'])\n",
    "train_master['UserInfo_8_20_province_same'] = (train_master['UserInfo_7']==train_master['UserInfo_19'])|(train_master['UserInfo_7']+u\"省\"==train_master[\\\n",
    "'UserInfo_19'])\n",
    "\n",
    "stock_data  = pd.read_csv(train_path+'stock_v4.csv')\n",
    "stock_data['date'] = pd.to_datetime(stock_data.date)\n",
    "tmp = train_master.merge(right =stock_data,how='left', left_on='ListingInfo',right_on='date')[['price',\\\n",
    "            'future_1m_index','Diff_future_1m_index','Ratio_future_1m_index', 'future_1m_up', 'future_1m_down', 'future_1m_up_2pct','future_1m_down_2pct',\\\n",
    "            'future_3m_index','Diff_future_3m_index','Ratio_future_3m_index', 'future_3m_up', 'future_3m_down', 'future_3m_up_2pct','future_3m_down_2pct',\\\n",
    "            'future_6m_index','Diff_future_6m_index','Ratio_future_6m_index', 'future_6m_up', 'future_6m_down', 'future_6m_up_2pct','future_6m_down_2pct',\\\n",
    "            'future_12m_index','Diff_future_12m_index','Ratio_future_12m_index','future_12m_up', 'future_12m_down', 'future_12m_up_2pct','future_12m_down_2pct',\\\n",
    "            ]].values\n",
    "\n",
    "train_master['price']=tmp[:,0]\n",
    "\n",
    "ipo_data  = pd.read_csv(train_path+'ipo_data_v2.csv')\n",
    "ipo_data['date'] = pd.to_datetime(ipo_data.date)\n",
    "tmp = train_master.merge(right =ipo_data,how='left', left_on='ListingInfo',right_on='date')[['cnt_ipo',\\\n",
    "            'amt_ipo','prob_ipo','ind_ipo_f7d','ind_ipo_f15d','ind_ipo_f30d','cnt_ipo_f7d','cnt_ipo_f15d',\\\n",
    "            'cnt_ipo_f30d','amt_ipo_f7d','amt_ipo_f15d','amt_ipo_f30d','prob_ipo_f7d','prob_ipo_f15d',\\\n",
    "            'prob_ipo_f30d'\\\n",
    "            ]].values\n",
    "\n",
    "train_master['cnt_ipo']=tmp[:,0]\n",
    "train_master['amt_ipo']=tmp[:,1]\n",
    "train_master['prob_ipo']=tmp[:,2]\n",
    "train_master['ind_ipo_f7d']=tmp[:,3]\n",
    "train_master['ind_ipo_f15d']=tmp[:,4]\n",
    "train_master['ind_ipo_f30d']=tmp[:,5]\n",
    "train_master['cnt_ipo_f7d']=tmp[:,6]\n",
    "train_master['cnt_ipo_f15d']=tmp[:,7]\n",
    "train_master['cnt_ipo_f30d']=tmp[:,8]\n",
    "train_master['amt_ipo_f7d']=tmp[:,9]\n",
    "train_master['amt_ipo_f15d']=tmp[:,10]\n",
    "train_master['amt_ipo_f30d']=tmp[:,11]\n",
    "train_master['prob_ipo_f7d']=tmp[:,12]\n",
    "train_master['prob_ipo_f15d']=tmp[:,13]\n",
    "train_master['prob_ipo_f30d']=tmp[:,14]\n",
    "\n",
    "\n",
    "for i in range(1,18):\n",
    "    tmplist = ['ThirdParty_Info_Period'+str(j)+'_'+str(i) for j in range(1,8)]\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_sum'] = train_master[tmplist].replace({-1:np.nan}).sum(axis=1,skipna=True).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_mean'] = train_master[tmplist].replace({-1:np.nan}).mean(axis=1,skipna=True).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_cnt'] = train_master[tmplist].replace({-1:np.nan}).count(axis=1).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_max'] = train_master[tmplist].replace({-1:np.nan}).max(axis=1,skipna=True).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_min'] = train_master[tmplist].replace({-1:np.nan}).min(axis=1,skipna=True).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_std'] = train_master[tmplist].replace({-1:np.nan}).std(axis=1,skipna=True).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_cmx'] = train_master['ThirdParty_Info_Period1'+'_'+str(i)]/train_master['ThirdParty_Info'+'_'+str(i)+'_max']\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_cav'] = train_master['ThirdParty_Info_Period1'+'_'+str(i)]/train_master['ThirdParty_Info'+'_'+str(i)+'_mean']\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_msn'] = train_master[tmplist].apply(func=msn,axis=1).fillna(9999)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_msz'] = train_master[tmplist].apply(func=msz,axis=1).fillna(9999)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_msx'] = train_master[tmplist].apply(func=msx,axis=1).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_num'] = train_master[tmplist].apply(func=num,axis=1).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_nuz'] = train_master[tmplist].apply(func=nuz,axis=1).fillna(-1)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_bup_6'] = train_master[tmplist].replace({-1:np.nan}).\\\n",
    "    apply(lambda x:1 if x.iloc[0]>=x.iloc[1]>=x.iloc[2]>=x.iloc[3]>=x.iloc[4]>=x.iloc[5] else 0)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_bud_6'] = train_master[tmplist].replace({-1:np.nan}).\\\n",
    "    apply(lambda x:1 if x.iloc[0]<=x.iloc[1]<=x.iloc[2]>=x.iloc[3]>=x.iloc[4]>=x.iloc[5] else 0)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_bup_3'] = train_master[tmplist].replace({-1:np.nan}).\\\n",
    "    apply(lambda x:1 if x.iloc[0]>=x.iloc[1]>=x.iloc[2] else 0)\n",
    "    train_master['ThirdParty_Info'+'_'+str(i)+'_bud_3'] = train_master[tmplist].replace({-1:np.nan}).\\\n",
    "    apply(lambda x:1 if x.iloc[0]<=x.iloc[1]<=x.iloc[2] else 0)\n",
    "    train_master = train_master.join(train_master[tmplist].replace({-1:np.nan}).rank(axis=1,method='min',ascending=False).fillna(-1),how='left',rsuffix='Rank_')\n",
    "\n",
    "'''train_master[train_master['ThirdParty_Info_Period1_1']>=200]['ThirdParty_Info_Period1_1']=200\n",
    "train_master[train_master['ThirdParty_Info_Period2_1']>=200]['ThirdParty_Info_Period2_1']=200\n",
    "train_master[train_master['ThirdParty_Info_Period3_1']>=200]['ThirdParty_Info_Period3_1']=200\n",
    "train_master[train_master['ThirdParty_Info_Period4_1']>=200]['ThirdParty_Info_Period4_1']=200\n",
    "train_master[train_master['ThirdParty_Info_Period5_1']>=200]['ThirdParty_Info_Period5_1']=200\n",
    "train_master[train_master['ThirdParty_Info_Period6_1']>=200]['ThirdParty_Info_Period6_1']=200\n",
    "train_master[train_master['ThirdParty_Info_Period7_1']>=200]['ThirdParty_Info_Period7_1']=200\n",
    "train_master[train_master['ThirdParty_Info_Period1_2']>=170]['ThirdParty_Info_Period1_2']=170\n",
    "train_master[train_master['ThirdParty_Info_Period2_2']>=170]['ThirdParty_Info_Period2_2']=170\n",
    "train_master[train_master['ThirdParty_Info_Period3_2']>=170]['ThirdParty_Info_Period3_2']=170\n",
    "train_master[train_master['ThirdParty_Info_Period4_2']>=170]['ThirdParty_Info_Period4_2']=170\n",
    "train_master[train_master['ThirdParty_Info_Period5_2']>=170]['ThirdParty_Info_Period5_2']=170\n",
    "train_master[train_master['ThirdParty_Info_Period6_2']>=170]['ThirdParty_Info_Period6_2']=170\n",
    "train_master[train_master['ThirdParty_Info_Period7_2']>=170]['ThirdParty_Info_Period7_2']=170\n",
    "train_master[train_master['ThirdParty_Info_Period1_3']>=1000]['ThirdParty_Info_Period1_3']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period2_3']>=1000]['ThirdParty_Info_Period2_3']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period3_3']>=1000]['ThirdParty_Info_Period3_3']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period4_3']>=1000]['ThirdParty_Info_Period4_3']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period5_3']>=1000]['ThirdParty_Info_Period5_3']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period6_3']>=1000]['ThirdParty_Info_Period6_3']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period7_3']>=1000]['ThirdParty_Info_Period7_3']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period1_4']>=1000]['ThirdParty_Info_Period1_4']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period2_4']>=1000]['ThirdParty_Info_Period2_4']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period3_4']>=1000]['ThirdParty_Info_Period3_4']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period4_4']>=1000]['ThirdParty_Info_Period4_4']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period5_4']>=1000]['ThirdParty_Info_Period5_4']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period6_4']>=1000]['ThirdParty_Info_Period6_4']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period7_4']>=1000]['ThirdParty_Info_Period7_4']=1000\n",
    "train_master[train_master['ThirdParty_Info_Period1_5']>=300]['ThirdParty_Info_Period1_5']=300\n",
    "train_master[train_master['ThirdParty_Info_Period2_5']>=300]['ThirdParty_Info_Period2_5']=300\n",
    "train_master[train_master['ThirdParty_Info_Period3_5']>=300]['ThirdParty_Info_Period3_5']=300\n",
    "train_master[train_master['ThirdParty_Info_Period4_5']>=300]['ThirdParty_Info_Period4_5']=300\n",
    "train_master[train_master['ThirdParty_Info_Period5_5']>=300]['ThirdParty_Info_Period5_5']=300\n",
    "train_master[train_master['ThirdParty_Info_Period6_5']>=300]['ThirdParty_Info_Period6_5']=300\n",
    "train_master[train_master['ThirdParty_Info_Period7_5']>=300]['ThirdParty_Info_Period7_5']=300\n",
    "train_master[train_master['ThirdParty_Info_Period1_6']>=250]['ThirdParty_Info_Period1_6']=250\n",
    "train_master[train_master['ThirdParty_Info_Period2_6']>=250]['ThirdParty_Info_Period2_6']=250\n",
    "train_master[train_master['ThirdParty_Info_Period3_6']>=250]['ThirdParty_Info_Period3_6']=250\n",
    "train_master[train_master['ThirdParty_Info_Period4_6']>=250]['ThirdParty_Info_Period4_6']=250\n",
    "train_master[train_master['ThirdParty_Info_Period5_6']>=250]['ThirdParty_Info_Period5_6']=250\n",
    "train_master[train_master['ThirdParty_Info_Period6_6']>=250]['ThirdParty_Info_Period6_6']=250\n",
    "train_master[train_master['ThirdParty_Info_Period7_6']>=250]['ThirdParty_Info_Period7_6']=250\n",
    "train_master[train_master['ThirdParty_Info_Period1_7']>=1400]['ThirdParty_Info_Period1_7']=1400\n",
    "train_master[train_master['ThirdParty_Info_Period2_7']>=1400]['ThirdParty_Info_Period2_7']=1400\n",
    "train_master[train_master['ThirdParty_Info_Period3_7']>=1400]['ThirdParty_Info_Period3_7']=1400\n",
    "train_master[train_master['ThirdParty_Info_Period4_7']>=1400]['ThirdParty_Info_Period4_7']=1400\n",
    "train_master[train_master['ThirdParty_Info_Period5_7']>=1400]['ThirdParty_Info_Period5_7']=1400\n",
    "train_master[train_master['ThirdParty_Info_Period6_7']>=1400]['ThirdParty_Info_Period6_7']=1400\n",
    "train_master[train_master['ThirdParty_Info_Period7_7']>=1400]['ThirdParty_Info_Period7_7']=1400\n",
    "train_master[train_master['ThirdParty_Info_Period1_8']>=500]['ThirdParty_Info_Period1_8']=500\n",
    "train_master[train_master['ThirdParty_Info_Period2_8']>=500]['ThirdParty_Info_Period2_8']=500\n",
    "train_master[train_master['ThirdParty_Info_Period3_8']>=500]['ThirdParty_Info_Period3_8']=500\n",
    "train_master[train_master['ThirdParty_Info_Period4_8']>=500]['ThirdParty_Info_Period4_8']=500\n",
    "train_master[train_master['ThirdParty_Info_Period5_8']>=500]['ThirdParty_Info_Period5_8']=500\n",
    "train_master[train_master['ThirdParty_Info_Period6_8']>=500]['ThirdParty_Info_Period6_8']=500\n",
    "train_master[train_master['ThirdParty_Info_Period7_8']>=500]['ThirdParty_Info_Period7_8']=500\n",
    "train_master[train_master['ThirdParty_Info_Period1_9']>=30]['ThirdParty_Info_Period1_9']=30\n",
    "train_master[train_master['ThirdParty_Info_Period2_9']>=30]['ThirdParty_Info_Period2_9']=30\n",
    "train_master[train_master['ThirdParty_Info_Period3_9']>=30]['ThirdParty_Info_Period3_9']=30\n",
    "train_master[train_master['ThirdParty_Info_Period4_9']>=30]['ThirdParty_Info_Period4_9']=30\n",
    "train_master[train_master['ThirdParty_Info_Period5_9']>=30]['ThirdParty_Info_Period5_9']=30\n",
    "train_master[train_master['ThirdParty_Info_Period6_9']>=30]['ThirdParty_Info_Period6_9']=30\n",
    "train_master[train_master['ThirdParty_Info_Period7_9']>=30]['ThirdParty_Info_Period7_9']=30\n",
    "train_master[train_master['ThirdParty_Info_Period1_10']>=7]['ThirdParty_Info_Period1_10']=7\n",
    "train_master[train_master['ThirdParty_Info_Period2_10']>=7]['ThirdParty_Info_Period2_10']=7\n",
    "train_master[train_master['ThirdParty_Info_Period3_10']>=7]['ThirdParty_Info_Period3_10']=7\n",
    "train_master[train_master['ThirdParty_Info_Period4_10']>=7]['ThirdParty_Info_Period4_10']=7\n",
    "train_master[train_master['ThirdParty_Info_Period5_10']>=7]['ThirdParty_Info_Period5_10']=7\n",
    "train_master[train_master['ThirdParty_Info_Period6_10']>=7]['ThirdParty_Info_Period6_10']=7\n",
    "train_master[train_master['ThirdParty_Info_Period7_10']>=7]['ThirdParty_Info_Period7_10']=7\n",
    "train_master[train_master['ThirdParty_Info_Period1_11']>=70]['ThirdParty_Info_Period1_11']=70\n",
    "train_master[train_master['ThirdParty_Info_Period2_11']>=70]['ThirdParty_Info_Period2_11']=70\n",
    "train_master[train_master['ThirdParty_Info_Period3_11']>=70]['ThirdParty_Info_Period3_11']=70\n",
    "train_master[train_master['ThirdParty_Info_Period4_11']>=70]['ThirdParty_Info_Period4_11']=70\n",
    "train_master[train_master['ThirdParty_Info_Period5_11']>=70]['ThirdParty_Info_Period5_11']=70\n",
    "train_master[train_master['ThirdParty_Info_Period6_11']>=70]['ThirdParty_Info_Period6_11']=70\n",
    "train_master[train_master['ThirdParty_Info_Period7_11']>=70]['ThirdParty_Info_Period7_11']=70\n",
    "train_master[train_master['ThirdParty_Info_Period1_12']>=15]['ThirdParty_Info_Period1_12']=15\n",
    "train_master[train_master['ThirdParty_Info_Period2_12']>=15]['ThirdParty_Info_Period2_12']=15\n",
    "train_master[train_master['ThirdParty_Info_Period3_12']>=15]['ThirdParty_Info_Period3_12']=15\n",
    "train_master[train_master['ThirdParty_Info_Period4_12']>=15]['ThirdParty_Info_Period4_12']=15\n",
    "train_master[train_master['ThirdParty_Info_Period5_12']>=15]['ThirdParty_Info_Period5_12']=15\n",
    "train_master[train_master['ThirdParty_Info_Period6_12']>=15]['ThirdParty_Info_Period6_12']=15\n",
    "train_master[train_master['ThirdParty_Info_Period7_12']>=15]['ThirdParty_Info_Period7_12']=15\n",
    "train_master[train_master['ThirdParty_Info_Period1_13']>=100000]['ThirdParty_Info_Period1_13']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period2_13']>=100000]['ThirdParty_Info_Period2_13']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period3_13']>=100000]['ThirdParty_Info_Period3_13']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period4_13']>=100000]['ThirdParty_Info_Period4_13']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period5_13']>=100000]['ThirdParty_Info_Period5_13']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period6_13']>=100000]['ThirdParty_Info_Period6_13']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period7_13']>=100000]['ThirdParty_Info_Period7_13']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period1_14']>=80000]['ThirdParty_Info_Period1_14']=80000\n",
    "train_master[train_master['ThirdParty_Info_Period2_14']>=80000]['ThirdParty_Info_Period2_14']=80000\n",
    "train_master[train_master['ThirdParty_Info_Period3_14']>=80000]['ThirdParty_Info_Period3_14']=80000\n",
    "train_master[train_master['ThirdParty_Info_Period4_14']>=80000]['ThirdParty_Info_Period4_14']=80000\n",
    "train_master[train_master['ThirdParty_Info_Period5_14']>=80000]['ThirdParty_Info_Period5_14']=80000\n",
    "train_master[train_master['ThirdParty_Info_Period6_14']>=80000]['ThirdParty_Info_Period6_14']=80000\n",
    "train_master[train_master['ThirdParty_Info_Period7_14']>=80000]['ThirdParty_Info_Period7_14']=80000\n",
    "train_master[train_master['ThirdParty_Info_Period1_15']>=20000]['ThirdParty_Info_Period1_15']=20000\n",
    "train_master[train_master['ThirdParty_Info_Period2_15']>=20000]['ThirdParty_Info_Period2_15']=20000\n",
    "train_master[train_master['ThirdParty_Info_Period3_15']>=20000]['ThirdParty_Info_Period3_15']=20000\n",
    "train_master[train_master['ThirdParty_Info_Period4_15']>=20000]['ThirdParty_Info_Period4_15']=20000\n",
    "train_master[train_master['ThirdParty_Info_Period5_15']>=20000]['ThirdParty_Info_Period5_15']=20000\n",
    "train_master[train_master['ThirdParty_Info_Period6_15']>=20000]['ThirdParty_Info_Period6_15']=20000\n",
    "train_master[train_master['ThirdParty_Info_Period7_15']>=20000]['ThirdParty_Info_Period7_15']=20000\n",
    "train_master[train_master['ThirdParty_Info_Period1_16']>=100000]['ThirdParty_Info_Period1_16']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period2_16']>=100000]['ThirdParty_Info_Period2_16']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period3_16']>=100000]['ThirdParty_Info_Period3_16']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period4_16']>=100000]['ThirdParty_Info_Period4_16']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period5_16']>=100000]['ThirdParty_Info_Period5_16']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period6_16']>=100000]['ThirdParty_Info_Period6_16']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period7_16']>=100000]['ThirdParty_Info_Period7_16']=100000\n",
    "train_master[train_master['ThirdParty_Info_Period1_17']>=50000]['ThirdParty_Info_Period1_17']=50000\n",
    "train_master[train_master['ThirdParty_Info_Period2_17']>=50000]['ThirdParty_Info_Period2_17']=50000\n",
    "train_master[train_master['ThirdParty_Info_Period3_17']>=50000]['ThirdParty_Info_Period3_17']=50000\n",
    "train_master[train_master['ThirdParty_Info_Period4_17']>=50000]['ThirdParty_Info_Period4_17']=50000\n",
    "train_master[train_master['ThirdParty_Info_Period5_17']>=50000]['ThirdParty_Info_Period5_17']=50000\n",
    "train_master[train_master['ThirdParty_Info_Period6_17']>=50000]['ThirdParty_Info_Period6_17']=50000\n",
    "train_master[train_master['ThirdParty_Info_Period7_17']>=50000]['ThirdParty_Info_Period7_17']=50000    '''\n",
    "train_master.fillna(-9999,inplace=True)\n",
    "\n",
    "from sklearn import preprocessing\n",
    "\n",
    "\n",
    "var_lst = [\\\n",
    "'UserInfo_2',\\\n",
    "'UserInfo_4',\\\n",
    "'UserInfo_5',\\\n",
    "'UserInfo_6',\\\n",
    "'UserInfo_7',\\\n",
    "'UserInfo_8',\\\n",
    "'UserInfo_9',\\\n",
    "'UserInfo_19',\\\n",
    "'UserInfo_20',\\\n",
    "'UserInfo_22',\\\n",
    "'UserInfo_23',\\\n",
    "'UserInfo_24',\\\n",
    "'Education_Info2',\\\n",
    "'Education_Info3',\\\n",
    "'Education_Info4',\\\n",
    "'Education_Info6',\\\n",
    "'Education_Info7',\\\n",
    "'Education_Info8',\\\n",
    "'WeblogInfo_19',\\\n",
    "'WeblogInfo_20',\\\n",
    "'WeblogInfo_21',\\\n",
    "'ListingInfo',\\\n",
    "'ListingInfo_M',\\\n",
    "'UserInfo_2_province',\\\n",
    "'UserInfo_4_province',\\\n",
    "'UserInfo_2_class',\\\n",
    "'UserInfo_4_class'\n",
    "]\n",
    "for var in var_lst:\n",
    "    le = preprocessing.LabelEncoder()\n",
    "    train_master[var]=le.fit_transform(train_master[var])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Data Merge\n",
    "train_final = train_master.join(train_part1,how='left')\n",
    "train_final = train_final.join(train_part2,how='left')\n",
    "\n",
    "drop_lst = [\\\n",
    "'WeblogInfo_49',\\\n",
    "'ListingInfo',\\\n",
    "\n",
    "'UserInfo_2',\\\n",
    "'UserInfo_20',\\\n",
    "'UserInfo_4',\\\n",
    "'UserInfo_8',\\\n",
    "]\n",
    "train_final.drop(drop_lst,axis=1,inplace=True)\n",
    "\n",
    "print train_final.shape\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "code_lst=[\\\n",
    "'Education_Info2',\\\n",
    "'Education_Info3',\\\n",
    "'Education_Info4',\\\n",
    "'Education_Info6',\\\n",
    "'Education_Info8',\\\n",
    "'ListingInfo_M',\\\n",
    "'SocialNetwork_1',\\\n",
    "'SocialNetwork_11',\\\n",
    "'SocialNetwork_12',\\\n",
    "'SocialNetwork_13',\\\n",
    "'SocialNetwork_14',\\\n",
    "'SocialNetwork_17',\\\n",
    "'SocialNetwork_2',\\\n",
    "'SocialNetwork_7',\\\n",
    "'UserInfo_1',\\\n",
    "'UserInfo_10',\\\n",
    "'UserInfo_11',\\\n",
    "'UserInfo_12',\\\n",
    "'UserInfo_13',\\\n",
    "'UserInfo_14',\\\n",
    "'UserInfo_15',\\\n",
    "'UserInfo_16',\\\n",
    "'UserInfo_19',\\\n",
    "'UserInfo_2_class',\\\n",
    "'UserInfo_2_province',\\\n",
    "'UserInfo_22',\\\n",
    "'UserInfo_23',\\\n",
    "'UserInfo_3',\\\n",
    "'UserInfo_4_class',\\\n",
    "'UserInfo_4_province',\\\n",
    "'UserInfo_5',\\\n",
    "'UserInfo_6',\\\n",
    "'UserInfo_7',\\\n",
    "'UserInfo_9',\\\n",
    "'WeblogInfo_1',\\\n",
    "'WeblogInfo_11',\\\n",
    "'WeblogInfo_12',\\\n",
    "'WeblogInfo_13',\\\n",
    "'WeblogInfo_19',\\\n",
    "'WeblogInfo_2',\\\n",
    "'WeblogInfo_20',\\\n",
    "'WeblogInfo_21',\\\n",
    "'WeblogInfo_23',\\\n",
    "'WeblogInfo_24',\\\n",
    "'WeblogInfo_25',\\\n",
    "'WeblogInfo_26',\\\n",
    "'WeblogInfo_27',\\\n",
    "'WeblogInfo_28',\\\n",
    "'WeblogInfo_29',\\\n",
    "'WeblogInfo_3',\\\n",
    "'WeblogInfo_30',\\\n",
    "'WeblogInfo_31',\\\n",
    "'WeblogInfo_32',\\\n",
    "'WeblogInfo_33',\\\n",
    "'WeblogInfo_34',\\\n",
    "'WeblogInfo_35',\\\n",
    "'WeblogInfo_36',\\\n",
    "'WeblogInfo_37',\\\n",
    "'WeblogInfo_38',\\\n",
    "'WeblogInfo_39',\\\n",
    "'WeblogInfo_40',\\\n",
    "'WeblogInfo_41',\\\n",
    "'WeblogInfo_42',\\\n",
    "'WeblogInfo_43',\\\n",
    "'WeblogInfo_44',\\\n",
    "'WeblogInfo_45',\\\n",
    "'WeblogInfo_46',\\\n",
    "'WeblogInfo_47',\\\n",
    "'WeblogInfo_48',\\\n",
    "'WeblogInfo_50',\\\n",
    "'WeblogInfo_51',\\\n",
    "'WeblogInfo_52',\\\n",
    "'WeblogInfo_53',\\\n",
    "'WeblogInfo_54',\\\n",
    "'WeblogInfo_55',\\\n",
    "'WeblogInfo_56',\\\n",
    "'WeblogInfo_57',\\\n",
    "'WeblogInfo_58',\\\n",
    "]\n",
    "enc = preprocessing.OneHotEncoder()\n",
    "train_final_one = train_final.join(pd.DataFrame(enc.fit_transform(train_final[code_lst].replace({-1:9999,-9999:9999})).toarray(),index=train_final.index),how='left')\n",
    "train_final_one.to_csv(train_path+'train_final_data.csv')\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "varlst = [\\\n",
    "'ThirdParty_Info_Period1_5',\\\n",
    "'ThirdParty_Info_Period5_4',\\\n",
    "'ThirdParty_Info_Period3_5',\\\n",
    "'ThirdParty_Info_10_max',\\\n",
    "'ThirdParty_Info_9_sum',\\\n",
    "'ThirdParty_Info_10_mean',\\\n",
    "'ThirdParty_Info_Period2_4',\\\n",
    "'ThirdParty_Info_10_nuz',\\\n",
    "'ThirdParty_Info_Period4_5',\\\n",
    "'ThirdParty_Info_10_std',\\\n",
    "'ThirdParty_Info_Period6_6',\\\n",
    "'ThirdParty_Info_10_sum',\\\n",
    "'ThirdParty_Info_Period1_14',\\\n",
    "'ThirdParty_Info_11_cav',\\\n",
    "'ThirdParty_Info_Period2_12',\\\n",
    "'ThirdParty_Info_11_cmx',\\\n",
    "'ThirdParty_Info_Period3_13',\\\n",
    "'ThirdParty_Info_11_max',\\\n",
    "'ThirdParty_Info_Period4_13',\\\n",
    "'ThirdParty_Info_11_mean',\\\n",
    "'ThirdParty_Info_Period5_13Rank_',\\\n",
    "'ThirdParty_Info_11_min',\\\n",
    "'ThirdParty_Info_Period6_14',\\\n",
    "'ThirdParty_Info_11_std',\\\n",
    "'WeblogInfo_16',\\\n",
    "'ThirdParty_Info_11_sum',\\\n",
    "'ThirdParty_Info_Period1_11Rank_',\\\n",
    "'ThirdParty_Info_12_cav',\\\n",
    "'ThirdParty_Info_Period1_2',\\\n",
    "'ThirdParty_Info_12_max',\\\n",
    "'ThirdParty_Info_Period1_8',\\\n",
    "'ThirdParty_Info_12_mean',\\\n",
    "'ThirdParty_Info_Period2_16',\\\n",
    "'ThirdParty_Info_12_std',\\\n",
    "'ThirdParty_Info_Period2_8',\\\n",
    "'ThirdParty_Info_12_sum',\\\n",
    "'ThirdParty_Info_Period3_17',\\\n",
    "'ThirdParty_Info_13_cav',\\\n",
    "'ThirdParty_Info_Period4_1',\\\n",
    "'ThirdParty_Info_13_cmx',\\\n",
    "'ThirdParty_Info_Period4_17',\\\n",
    "'ThirdParty_Info_13_max',\\\n",
    "'ThirdParty_Info_Period4_9',\\\n",
    "'ThirdParty_Info_13_mean',\\\n",
    "'ThirdParty_Info_Period5_17',\\\n",
    "'ThirdParty_Info_13_min',\\\n",
    "'ThirdParty_Info_Period5_8',\\\n",
    "'ThirdParty_Info_13_std',\\\n",
    "'ThirdParty_Info_Period6_2',\\\n",
    "'ThirdParty_Info_13_sum',\\\n",
    "'UserInfo_18',\\\n",
    "'ThirdParty_Info_14_cav',\\\n",
    "'WeblogInfo_5',\\\n",
    "'ThirdParty_Info_14_cmx',\\\n",
    "'ThirdParty_Info_Period1_10',\\\n",
    "'ThirdParty_Info_14_max',\\\n",
    "'ThirdParty_Info_Period1_13',\\\n",
    "'ThirdParty_Info_14_mean',\\\n",
    "'ThirdParty_Info_Period1_16',\\\n",
    "'ThirdParty_Info_14_min',\\\n",
    "'ThirdParty_Info_Period1_3',\\\n",
    "'ThirdParty_Info_14_std',\\\n",
    "'ThirdParty_Info_Period1_6',\\\n",
    "'ThirdParty_Info_14_sum',\\\n",
    "'ThirdParty_Info_Period2_1',\\\n",
    "'ThirdParty_Info_15_cav',\\\n",
    "'ThirdParty_Info_Period2_14',\\\n",
    "'ThirdParty_Info_15_cmx',\\\n",
    "'ThirdParty_Info_Period2_2',\\\n",
    "'ThirdParty_Info_15_max',\\\n",
    "'ThirdParty_Info_Period2_6',\\\n",
    "'ThirdParty_Info_15_mean',\\\n",
    "'ThirdParty_Info_Period3_11Rank_',\\\n",
    "'ThirdParty_Info_15_min',\\\n",
    "'ThirdParty_Info_Period3_15',\\\n",
    "'ThirdParty_Info_15_std',\\\n",
    "'ThirdParty_Info_Period3_3',\\\n",
    "'ThirdParty_Info_15_sum',\\\n",
    "'ThirdParty_Info_Period3_7',\\\n",
    "'ThirdParty_Info_16_cav',\\\n",
    "'ThirdParty_Info_Period4_11',\\\n",
    "'ThirdParty_Info_16_cmx',\\\n",
    "'ThirdParty_Info_Period4_15',\\\n",
    "'ThirdParty_Info_16_max',\\\n",
    "'ThirdParty_Info_Period4_3',\\\n",
    "'ThirdParty_Info_16_mean',\\\n",
    "'ThirdParty_Info_Period4_7',\\\n",
    "'ThirdParty_Info_16_min',\\\n",
    "'ThirdParty_Info_Period5_11',\\\n",
    "'ThirdParty_Info_16_std',\\\n",
    "'ThirdParty_Info_Period5_15',\\\n",
    "'ThirdParty_Info_16_sum',\\\n",
    "'ThirdParty_Info_Period5_2',\\\n",
    "'ThirdParty_Info_17_cav',\\\n",
    "'ThirdParty_Info_Period5_6',\\\n",
    "'ThirdParty_Info_17_cmx',\\\n",
    "'ThirdParty_Info_Period6_11',\\\n",
    "'ThirdParty_Info_17_max',\\\n",
    "'ThirdParty_Info_Period6_16',\\\n",
    "'ThirdParty_Info_17_mean',\\\n",
    "'ThirdParty_Info_Period6_4',\\\n",
    "'ThirdParty_Info_17_min',\\\n",
    "'ThirdParty_Info_Period6_8',\\\n",
    "'ThirdParty_Info_17_std',\\\n",
    "'UserInfo_4_8_same',\\\n",
    "'ThirdParty_Info_17_sum',\\\n",
    "'WeblogInfo_18',\\\n",
    "'ThirdParty_Info_2_cav',\\\n",
    "'WeblogInfo_7',\\\n",
    "'ThirdParty_Info_2_cmx',\\\n",
    "'ThirdParty_Info_Period1_1',\\\n",
    "'ThirdParty_Info_2_max',\\\n",
    "'ThirdParty_Info_Period1_11',\\\n",
    "'ThirdParty_Info_2_mean',\\\n",
    "'ThirdParty_Info_Period1_12',\\\n",
    "'ThirdParty_Info_2_min',\\\n",
    "'ThirdParty_Info_Period1_13Rank_',\\\n",
    "'ThirdParty_Info_2_msx',\\\n",
    "'ThirdParty_Info_Period1_15',\\\n",
    "'ThirdParty_Info_2_nuz',\\\n",
    "'ThirdParty_Info_Period1_17',\\\n",
    "'ThirdParty_Info_2_std',\\\n",
    "'ThirdParty_Info_Period1_2Rank_',\\\n",
    "'ThirdParty_Info_2_sum',\\\n",
    "'ThirdParty_Info_Period1_4',\\\n",
    "'ThirdParty_Info_3_cav',\\\n",
    "'ThirdParty_Info_Period1_5Rank_',\\\n",
    "'ThirdParty_Info_3_cmx',\\\n",
    "'ThirdParty_Info_Period1_7',\\\n",
    "'ThirdParty_Info_3_max',\\\n",
    "'ThirdParty_Info_Period1_9',\\\n",
    "'ThirdParty_Info_3_mean',\\\n",
    "'ThirdParty_Info_Period2_11',\\\n",
    "'ThirdParty_Info_3_min',\\\n",
    "'ThirdParty_Info_Period2_13',\\\n",
    "'ThirdParty_Info_3_std',\\\n",
    "'ThirdParty_Info_Period2_15',\\\n",
    "'ThirdParty_Info_3_sum',\\\n",
    "'ThirdParty_Info_Period2_17',\\\n",
    "'ThirdParty_Info_4_cav',\\\n",
    "'ThirdParty_Info_Period2_3',\\\n",
    "'ThirdParty_Info_4_cmx',\\\n",
    "'ThirdParty_Info_Period2_5',\\\n",
    "'ThirdParty_Info_4_max',\\\n",
    "'ThirdParty_Info_Period2_7',\\\n",
    "'ThirdParty_Info_4_mean',\\\n",
    "'ThirdParty_Info_Period3_1',\\\n",
    "'ThirdParty_Info_4_min',\\\n",
    "'ThirdParty_Info_Period3_12',\\\n",
    "'ThirdParty_Info_4_std',\\\n",
    "'ThirdParty_Info_Period3_14',\\\n",
    "'ThirdParty_Info_4_sum',\\\n",
    "'ThirdParty_Info_Period3_16',\\\n",
    "'ThirdParty_Info_5_cav',\\\n",
    "'ThirdParty_Info_Period3_2',\\\n",
    "'ThirdParty_Info_5_cmx',\\\n",
    "'ThirdParty_Info_Period3_4',\\\n",
    "'ThirdParty_Info_5_max',\\\n",
    "'ThirdParty_Info_Period3_6',\\\n",
    "'ThirdParty_Info_5_mean',\\\n",
    "'ThirdParty_Info_Period3_8',\\\n",
    "'ThirdParty_Info_5_min',\\\n",
    "'ThirdParty_Info_Period4_10Rank_',\\\n",
    "'ThirdParty_Info_5_std',\\\n",
    "'ThirdParty_Info_Period4_12',\\\n",
    "'ThirdParty_Info_5_sum',\\\n",
    "'ThirdParty_Info_Period4_14',\\\n",
    "'ThirdParty_Info_6_cav',\\\n",
    "'ThirdParty_Info_Period4_16',\\\n",
    "'ThirdParty_Info_6_cmx',\\\n",
    "'ThirdParty_Info_Period4_2',\\\n",
    "'ThirdParty_Info_6_max',\\\n",
    "'ThirdParty_Info_Period4_4',\\\n",
    "'ThirdParty_Info_6_mean',\\\n",
    "'ThirdParty_Info_Period4_6',\\\n",
    "'ThirdParty_Info_6_min',\\\n",
    "'ThirdParty_Info_Period4_8',\\\n",
    "'ThirdParty_Info_6_std',\\\n",
    "'ThirdParty_Info_Period5_1',\\\n",
    "'ThirdParty_Info_6_sum',\\\n",
    "'ThirdParty_Info_Period5_13',\\\n",
    "'ThirdParty_Info_7_cav',\\\n",
    "'ThirdParty_Info_Period5_14',\\\n",
    "'ThirdParty_Info_7_cmx',\\\n",
    "'ThirdParty_Info_Period5_16',\\\n",
    "'ThirdParty_Info_7_max',\\\n",
    "'ThirdParty_Info_Period5_17Rank_',\\\n",
    "'ThirdParty_Info_7_mean',\\\n",
    "'ThirdParty_Info_Period5_3',\\\n",
    "'ThirdParty_Info_7_min',\\\n",
    "'ThirdParty_Info_Period5_5',\\\n",
    "'ThirdParty_Info_7_std',\\\n",
    "'ThirdParty_Info_Period5_7',\\\n",
    "'ThirdParty_Info_7_sum',\\\n",
    "'ThirdParty_Info_Period6_1',\\\n",
    "'ThirdParty_Info_8_cav',\\\n",
    "'ThirdParty_Info_Period6_13',\\\n",
    "'ThirdParty_Info_8_cmx',\\\n",
    "'ThirdParty_Info_Period6_15',\\\n",
    "'ThirdParty_Info_8_max',\\\n",
    "'ThirdParty_Info_Period6_17',\\\n",
    "'ThirdParty_Info_8_mean',\\\n",
    "'ThirdParty_Info_Period6_3',\\\n",
    "'ThirdParty_Info_8_min',\\\n",
    "'ThirdParty_Info_Period6_5',\\\n",
    "'ThirdParty_Info_8_msx',\\\n",
    "'ThirdParty_Info_Period6_7',\\\n",
    "'ThirdParty_Info_8_std',\\\n",
    "'UserInfo_17',\\\n",
    "'ThirdParty_Info_8_sum',\\\n",
    "'UserInfo_2_4_same',\\\n",
    "'ThirdParty_Info_9_cav',\\\n",
    "'WeblogInfo_15',\\\n",
    "'ThirdParty_Info_9_cmx',\\\n",
    "'WeblogInfo_17',\\\n",
    "'ThirdParty_Info_9_max',\\\n",
    "'WeblogInfo_4',\\\n",
    "'ThirdParty_Info_9_mean',\\\n",
    "'WeblogInfo_6',\\\n",
    "'ThirdParty_Info_9_nuz',\\\n",
    "'WeblogInfo_8',\\\n",
    "'ThirdParty_Info_9_std',\\\n",
    "'ThirdParty_Info_10_cav',\\\n",
    "'SocialNetwork_3',\\\n",
    "'Dayslogtolisting',\\\n",
    "'daysfirst_type_act_21_2',\\\n",
    "'7',\\\n",
    "'ratio_cnt_loginfo41_4_listday',\\\n",
    "'20',\\\n",
    "'cnt_weekday0',\\\n",
    "'24',\\\n",
    "'dayslast_RESIDENCEADDRESS',\\\n",
    "'57',\\\n",
    "'price',\\\n",
    "'58',\\\n",
    "'ratio_cnt_loginfo47_4_listday',\\\n",
    "'77',\\\n",
    "'ThirdParty_Info_1_nuz',\\\n",
    "'79',\\\n",
    "'daysfirst_type_act_0_1',\\\n",
    "'86',\\\n",
    "'Daysfirsttolisting',\\\n",
    "'92',\\\n",
    "'dayslast_type_act_2_1',\\\n",
    "'98',\\\n",
    "'Education_Info5',\\\n",
    "'99',\\\n",
    "'ratio_cnt_first_log',\\\n",
    "'100',\\\n",
    "'ratio_cnt_loginfo43_2_listday',\\\n",
    "'101',\\\n",
    "'ratio_cnt_update_MOBILEPHONE_listday',\\\n",
    "'106',\\\n",
    "'ThirdParty_Info_1_cmx',\\\n",
    "'107',\\\n",
    "'cnt_update_listday_3',\\\n",
    "'108',\\\n",
    "'days_since_most_log',\\\n",
    "'112',\\\n",
    "'daysfirst_type_act_2_1',\\\n",
    "'114',\\\n",
    "'daysfirst_type_act_6_-4',\\\n",
    "'126',\\\n",
    "'dayslast_EDUCATIONID',\\\n",
    "'128',\\\n",
    "'dayslast_type_act_0_1',\\\n",
    "'150',\\\n",
    "'dayslast_type_act_6_-4',\\\n",
    "'165',\\\n",
    "'Duration_log',\\\n",
    "'232',\\\n",
    "'less_nation_info4',\\\n",
    "'238',\\\n",
    "'prob_ipo_f30d',\\\n",
    "'240',\\\n",
    "'ratio_cnt_loginfo40_1_listday',\\\n",
    "'253',\\\n",
    "'ratio_cnt_loginfo420_1_listday',\\\n",
    "'258',\\\n",
    "'ratio_cnt_loginfo46_-4_listday',\\\n",
    "'267',\\\n",
    "'ratio_cnt_update_EDUCATIONID_listday',\\\n",
    "'269',\\\n",
    "'ratio_cnt_update_TURNOVER_listday',\\\n",
    "'270',\\\n",
    "'SocialNetwork_9',\\\n",
    "'277',\\\n",
    "'ThirdParty_Info_1_mean',\\\n",
    "'287',\\\n",
    "'ThirdParty_Info_1_sum',\\\n",
    "'288',\\\n",
    "'cnt_update_listday_7',\\\n",
    "'291',\\\n",
    "'days_between_two_log',\\\n",
    "'294',\\\n",
    "'daysfirst_LASTUPDATEDATE',\\\n",
    "'409',\\\n",
    "'daysfirst_type_act_1_4',\\\n",
    "'410',\\\n",
    "'daysfirst_type_act_20_1',\\\n",
    "'454',\\\n",
    "'daysfirst_type_act_3_2',\\\n",
    "'463',\\\n",
    "'Daysfirstlogtolisting',\\\n",
    "'amt_ipo_f15d',\\\n",
    "'dayslast_CITYID',\\\n",
    "'amt_ipo_f30d',\\\n",
    "'dayslast_MOBILEPHONE',\\\n",
    "'amt_ipo_f7d',\\\n",
    "'dayslast_RESIDENCEPHONE',\\\n",
    "'avg_cnt_log',\\\n",
    "'dayslast_type_act_1_4',\\\n",
    "'cnt_ipo_f15d',\\\n",
    "'dayslast_type_act_20_1',\\\n",
    "'cnt_ipo_f30d',\\\n",
    "'Dayslogstd',\\\n",
    "'cnt_ipo_f7d',\\\n",
    "'Daysupdatetolisting',\\\n",
    "'cnt_log',\\\n",
    "'Education_Info1',\\\n",
    "'cnt_log_days_listday_7',\\\n",
    "'Education_Info7',\\\n",
    "'cnt_log_listday',\\\n",
    "'ListingInfo_weekno',\\\n",
    "'cnt_log_listday_15',\\\n",
    "'prob_ipo_f15d',\\\n",
    "'cnt_log_listday_3',\\\n",
    "'prob_ipo_f7d',\\\n",
    "'cnt_log_listday_30',\\\n",
    "'ratio_cnt_first_update',\\\n",
    "'cnt_log_listday_7',\\\n",
    "'ratio_cnt_loginfo41_1_listday',\\\n",
    "'cnt_log_type_actcnt_listday_0',\\\n",
    "'ratio_cnt_loginfo42_1_listday',\\\n",
    "'cnt_log_weekday1',\\\n",
    "'ratio_cnt_loginfo421_2_listday',\\\n",
    "'cnt_log_weekday3',\\\n",
    "'ratio_cnt_loginfo44_1_listday',\\\n",
    "'cnt_log_weekday6',\\\n",
    "'ratio_cnt_loginfo46_99_listday',\\\n",
    "'cnt_log4_days6_-4_listday',\\\n",
    "'ratio_cnt_update_BYUSERID_listday',\\\n",
    "'cnt_loginfo46_-4_listday',\\\n",
    "'ratio_cnt_update_LASTUPDATEDATE_listday',\\\n",
    "'cnt_loginfo46_-4_listday_0',\\\n",
    "'ratio_cnt_update_RESIDENCETYPEID_listday',\\\n",
    "'cnt_loginfo46_-4_listday_15',\\\n",
    "'SocialNetwork_10',\\\n",
    "'cnt_loginfo46_-4_listday_30',\\\n",
    "'SocialNetwork_8',\\\n",
    "'cnt_loginfo46_-4_listday_7',\\\n",
    "'ThirdParty_Info_1_cav',\\\n",
    "'cnt_loginfo47_4_listday_7',\\\n",
    "'ThirdParty_Info_1_max',\\\n",
    "'cnt_type_act_3_2',\\\n",
    "'ThirdParty_Info_1_min',\\\n",
    "'cnt_type_act_6_-4',\\\n",
    "'ThirdParty_Info_1_std',\\\n",
    "'cnt_update',\\\n",
    "'5',\\\n",
    "'ThirdParty_Info_Period3_10',\\\n",
    "'ThirdParty_Info_Period1_1Rank_',\\\n",
    "'ThirdParty_Info_Period3_13Rank_',\\\n",
    "'ThirdParty_Info_Period4_1Rank_',\\\n",
    "'ThirdParty_Info_Period1_14Rank_',\\\n",
    "'ThirdParty_Info_Period5_14Rank_',\\\n",
    "'ThirdParty_Info_Period3_11',\\\n",
    "'ThirdParty_Info_Period5_16Rank_',\\\n",
    "'UserInfo_24',\\\n",
    "'ThirdParty_Info_Period5_9',\\\n",
    "'ThirdParty_Info_Period2_6Rank_',\\\n",
    "'ThirdParty_Info_12_nuz',\\\n",
    "'ratio_cnt_update_RESIDENCEPHONE_listday',\\\n",
    "'260',\\\n",
    "'cnt_log_days_listday_15',\\\n",
    "'daysfirst_type_act_6_107',\\\n",
    "'cnt_first_log',\\\n",
    "'85',\\\n",
    "'daysfirst_type_act_1_1',\\\n",
    "'daysfirst_type_act_7_4',\\\n",
    "'cnt_loginfo47_4_listday_30',\\\n",
    "'12',\\\n",
    "'cnt_update_cnt_listday',\\\n",
    "'302',\\\n",
    "'cnt_weekday2',\\\n",
    "'dayslast_DISTRICTID',\\\n",
    "'daysfirst_QQ',\\\n",
    "'318',\\\n",
    "'daysfirst_type_act_1_3',\\\n",
    "'dayslast_HASBUYCAR',\\\n",
    "'less_nation_info2',\\\n",
    "'dayslast_LASTUPDATEDATE',\\\n",
    "'amt_ipo',\\\n",
    "'319',\\\n",
    "'88',\\\n",
    "'dayslast_QQ',\\\n",
    "'ratio_cnt_loginfo41_2_listday',\\\n",
    "'cnt_log_weekday0',\\\n",
    "'172',\\\n",
    "'402',\\\n",
    "'daysfirst_EDUCATIONID',\\\n",
    "'dayslast_type_act_1_1',\\\n",
    "'daysfirst_MOBILEPHONE',\\\n",
    "'dayslast_type_act_7_4',\\\n",
    "'daysfirst_RESIDENCEADDRESS',\\\n",
    "'cnt_log4_days6_99_listday',\\\n",
    "'daysfirst_type_act_1_2',\\\n",
    "'Daysupdatestd',\\\n",
    "'cnt_log_days_listday',\\\n",
    "'Duration_update',\\\n",
    "'cnt_log_days_listday_30',\\\n",
    "'257',\\\n",
    "'UserInfo_2_4_province_same',\\\n",
    "'ThirdParty_Info_12_cmx',\\\n",
    "'ThirdParty_Info_Period3_15Rank_',\\\n",
    "'ThirdParty_Info_Period2_10',\\\n",
    "'ThirdParty_Info_Period7_15Rank_',\\\n",
    "'ThirdParty_Info_Period3_4Rank_',\\\n",
    "'ThirdParty_Info_Period4_3Rank_',\\\n",
    "'ThirdParty_Info_13_msx',\\\n",
    "'cnt_first_update',\\\n",
    "'dayslast_type_act_0_12',\\\n",
    "'cnt_log_weekday2',\\\n",
    "'cnt_loginfo46_-4_listday_3',\\\n",
    "'dayslast_MARRIAGESTATUSID',\\\n",
    "'280',\\\n",
    "'dayslast_RESIDENCETYPEID',\\\n",
    "'283',\\\n",
    "'174',\\\n",
    "'daysfirst_DISTRICTID',\\\n",
    "'cnt_loginfo43_2_listday',\\\n",
    "'248',\\\n",
    "'dayslast_type_act_1_3',\\\n",
    "'497',\\\n",
    "'147',\\\n",
    "'cnt_log_weekday5',\\\n",
    "'ListingInfo_weekday',\\\n",
    "'ThirdParty_Info_Period1_16Rank_',\\\n",
    "'ThirdParty_Info_Period2_12Rank_',\\\n",
    "'UserInfo_2_20_same',\\\n",
    "'ThirdParty_Info_Period1_9Rank_',\\\n",
    "'ThirdParty_Info_Period4_8Rank_',\\\n",
    "'ThirdParty_Info_Period5_8Rank_',\\\n",
    "'ThirdParty_Info_Period4_9Rank_',\\\n",
    "'ThirdParty_Info_Period4_16Rank_',\\\n",
    "'ThirdParty_Info_Period5_11Rank_',\\\n",
    "'ThirdParty_Info_Period2_9',\\\n",
    "'ThirdParty_Info_Period1_7Rank_',\\\n",
    "'ThirdParty_Info_Period1_4Rank_',\\\n",
    "'ThirdParty_Info_Period3_8Rank_',\\\n",
    "'293',\\\n",
    "'dayslast_type_act_6_107',\\\n",
    "'162',\\\n",
    "'dayslast_type_act_1_2',\\\n",
    "'cnt_update_listday_30',\\\n",
    "'465',\\\n",
    "'daysfirst_PROVINCEID',\\\n",
    "'104',\\\n",
    "'daysfirst_type_act_0_12',\\\n",
    "'428',\\\n",
    "'cnt_log_2moretype_act_listday_0',\\\n",
    "'daysfirst_CITYID',\\\n",
    "'140',\\\n",
    "'cnt_loginfo47_4_listday_15',\\\n",
    "'cnt_log_weekday4',\\\n",
    "'ratio_cnt_update_COMPANYADDRESS_listday',\\\n",
    "'453',\\\n",
    "'ratio_cnt_update_COMPANYPHONE_listday',\\\n",
    "'cnt_update_2moreitem_listday_7',\\\n",
    "'ratio_cnt_update_DISTRICTID_listday',\\\n",
    "'dayslast_RESIDENCEYEARS',\\\n",
    "'dayslast_IDNUMBER',\\\n",
    "'81',\\\n",
    "'ratio_cnt_update_HASBUYCAR_listday',\\\n",
    "'dayslast_type_act_6_4',\\\n",
    "'cnt_LASTUPDATEDATE',\\\n",
    "'ratio_cnt_loginfo420_300_listday',\\\n",
    "'daysfirst_MARRIAGESTATUSID',\\\n",
    "'ratio_cnt_update_RESIDENCEADDRESS_listday',\\\n",
    "'cnt_update_cnt_listday_30',\\\n",
    "'ThirdParty_Info_6_msx',\\\n",
    "'ThirdParty_Info_Period4_11Rank_',\\\n",
    "'ThirdParty_Info_Period6_1Rank_',\\\n",
    "'ThirdParty_Info_Period2_13Rank_',\\\n",
    "'ThirdParty_Info_Period4_13Rank_',\\\n",
    "'ThirdParty_Info_3_msx',\\\n",
    "'ThirdParty_Info_Period3_7Rank_',\\\n",
    "'ThirdParty_Info_Period6_8Rank_',\\\n",
    "'ThirdParty_Info_Period2_3Rank_',\\\n",
    "'ThirdParty_Info_Period3_9',\\\n",
    "'ThirdParty_Info_Period7_6Rank_',\\\n",
    "'ThirdParty_Info_Period2_16Rank_',\\\n",
    "'daysfirst_HASBUYCAR',\\\n",
    "'ratio_cnt_loginfo40_12_listday',\\\n",
    "'daysfirst_RESIDENCEPHONE',\\\n",
    "'8',\\\n",
    "'ratio_cnt_loginfo41_3_listday',\\\n",
    "'181',\\\n",
    "'ratio_cnt_update_QQ_listday',\\\n",
    "'dayslast_PHONE',\\\n",
    "'168',\\\n",
    "'dayslast_REALNAME',\\\n",
    "'cnt_update_listday_15',\\\n",
    "'97',\\\n",
    "'days_between_two_update',\\\n",
    "'dayslast_type_act_3_2',\\\n",
    "'daysfirst_ISCASH',\\\n",
    "'14',\\\n",
    "          'target',\\\n",
    "          'test_ind'\n",
    "]\n",
    "train_final_subset = train_final_one[varlst]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_df = train_final_subset[(train_final_subset['test_ind']==0)|(train_final_subset['test_ind']==2)]\n",
    "test_df = train_final_subset[train_final_subset['test_ind']==1]\n",
    "\n",
    "dtrain  = xgb.DMatrix(train_df.drop(['target','test_ind'],axis=1),train_df.target)\n",
    "dval  = xgb.DMatrix(test_df.drop(['target','test_ind'],axis=1))\n",
    "scr_tk = []\n",
    "for i in range(10):\n",
    "    print \"The %d round start\" %(i)\n",
    "    params = {\"objective\": \"binary:logistic\", \"eta\": 0.02, \"max_depth\": 5, \"min_child_weight\": 15,\"silent\": 1, \"subsample\": 0.8,\"colsample_bytree\": 0.8,\\\n",
    "               \"eval_metric\":\"auc\",'seed':i*50, 'alpha':0,'lambda':1} \n",
    "    num_round = 1650\n",
    "    bst = xgb.train( params, dtrain, num_round,verbose_eval=100)\n",
    "    scr0 = bst.predict(dval)   \n",
    "    params = {\"objective\": \"binary:logistic\", \"eta\": 0.02, \"max_depth\": 4, \"min_child_weight\": 10,\"silent\": 1, \"subsample\": 0.8,\"colsample_bytree\": 0.8,\\\n",
    "               \"eval_metric\":\"auc\",'seed':i*50, 'alpha':0,'lambda':1} \n",
    "    num_round = 2200\n",
    "    bst = xgb.train( params, dtrain, num_round,verbose_eval=100)\n",
    "    scr1 = bst.predict(dval)   \n",
    "    params = {\"objective\": \"binary:logistic\", \"eta\": 0.02, \"max_depth\": 3, \"min_child_weight\": 5,\"silent\": 1, \"subsample\": 0.8,\"colsample_bytree\": 0.8,\\\n",
    "               \"eval_metric\":\"auc\",'seed':i*50, 'alpha':0,'lambda':1} \n",
    "    num_round = 3800 \n",
    "    bst = xgb.train( params, dtrain, num_round,verbose_eval=100)\n",
    "    scr2 = bst.predict(dval)\n",
    "    params = {\"objective\": \"binary:logistic\", \"eta\": 0.02, \"max_depth\": 6, \"min_child_weight\":15,\"silent\": 1, \"subsample\": 0.8,\"colsample_bytree\": 0.8,\\\n",
    "               \"eval_metric\":\"auc\",'seed':i*50, 'alpha':0,'lambda':1} \n",
    "    num_round = 1500\n",
    "    bst = xgb.train( params, dtrain, num_round,verbose_eval=100)\n",
    "    scr3 = bst.predict(dval)\n",
    "    test_df['score'+str(i)] = (scr0+scr1+scr2+scr3)/(4*1.0)\n",
    "    scr_tk.append([scr0,scr1,scr2,scr3])\n",
    "\n",
    "scr_test = test_df[['score'+str(i) for i in range(10)]].mean(axis=1)\n",
    "test_df['score'] = np.round(scr_test,4)\n",
    "test_df.to_csv(train_path+'test_score_ensemble0417.csv',encoding = 'utf-8', columns=['score'])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
